package com.woniuxy.happylife.suggest.controller;

import com.qiniu.common.QiniuException;
import com.woniuxy.happylife.entity.Image;
import com.woniuxy.happylife.entity.ResponseEntity;

import com.woniuxy.happylife.suggest.config.MultipartFileToFile;
import com.woniuxy.happylife.suggest.service.IQiniuService;
import com.woniuxy.happylife.suggest.service.ImageServie;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @Author Fu
 * @Date 2022-02-17 14:29
 */
@Slf4j
@CrossOrigin
@RestController
public class QiniuController {
    @Autowired
    private IQiniuService qiniuService;
    @Autowired
    ImageServie imageServie;
    @RequestMapping("uploadFile")
    public ResponseEntity testUpload(MultipartFile file ) throws Exception {
//        String result = qiniuService.uploadFile(
//                new File("C:\\Users\\venture\\Desktop\\aaa.jpg"), "aaa");
        log.info(file.getOriginalFilename());
        File file1 = MultipartFileToFile.multipartFileToFile(file);
        String result = qiniuService.uploadFile(file1,file.getOriginalFilename());
        log.info(result);

        imageServie.add(new Image(result,1));
        return new ResponseEntity(200,"上传成功",result);
    }

    @RequestMapping("delete")
    public void testDelete() throws QiniuException {
        String result = qiniuService.delete("aaa");
        System.out.println(result);
    }


}
